package com.zut.yyzx.config;

import com.zut.yyzx.interceptor.CheckTokenInterceptor;
import com.zut.yyzx.utils.DateConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private CheckTokenInterceptor checkTokenInterceptor;
    //向应用程序添加自定义的日期转换器（DateConverter）
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new DateConverter());
    }
    /**
     * 拦截器校验Token
      */
    //注册一个拦截器（CheckTokenInterceptor），该拦截器用于校验Token。
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            //定义排除登录接口

            //"/swagger-ui.html","/doc.html", "/swagger-resources/**",
            String[] swaggerExcludes = new String[]{"/webjars/**", "/login/**"};
            registry.addInterceptor(checkTokenInterceptor)
            .addPathPatterns("/**") //拦截所有的 url
            .excludePathPatterns("/user/login");//排除url: /user/login (登录)

    }
}
